From fb36b62f331a7cc5d3d10e53d6db086bf1c18e0c Mon Sep 17 00:00:00 2001 From: Matthew Leeds Date: Mon, 16 Jul 2018 14:54:57 -0700 Subject: [PATCH] lib/repo: Take exclusive lock while generating summary This ensures that commits aren't deleted and refs aren't added, removed, or updated while the summary is being generated. This is in preparation for adding a repo config option that will automatically regenerate the summary on every ref change. Closes: #1681 Approved by: jlebon --- src/libostree/ostree-repo.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index 92148b03..7acd0940 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -5394,6 +5394,8 @@ summary_add_ref_entry (OstreeRepo *self, * file, listed under the %OSTREE_SUMMARY_COLLECTION_MAP key. Collection IDs * and refs in %OSTREE_SUMMARY_COLLECTION_MAP are guaranteed to be in * lexicographic order. + * + * Locking: exclusive */ gboolean ostree_repo_regenerate_summary (OstreeRepo *self, @@ -5401,6 +5403,18 @@ ostree_repo_regenerate_summary (OstreeRepo *self, GCancellable *cancellable, GError **error) { + /* Take an exclusive lock. This makes sure the commits and deltas don't get + * deleted while generating the summary. It also means we can be sure refs + * won't be created/updated/deleted during the operation, without having to + * add exclusive locks to those operations which would prevent concurrent + * commits from working. + */ + g_autoptr(OstreeRepoAutoLock) lock = NULL; + lock = _ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_EXCLUSIVE, + cancellable, error); + if (!lock) + return FALSE; + g_auto(GVariantDict) additional_metadata_builder = OT_VARIANT_BUILDER_INITIALIZER; g_variant_dict_init (&additional_metadata_builder, additional_metadata); g_autoptr(GVariantBuilder) refs_builder = g_variant_builder_new (G_VARIANT_TYPE ("a(s(taya{sv}))")); -- 2.30.2